package mblog.staticfile;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.Writer;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import mblog.modules.blog.data.PostVO;

@Service
public class StaticFileService {
	
    @Resource
    Configuration cfg;

    public void freeMarkerContent2(Map<String,PostVO> root,String htmlName){
        try {
            Template temp = cfg.getTemplate("card/channel/view.ftl");
            //以classpath下面的static目录作为静态页面的存储目录，同时命名生成的静态html文件名称
            String path=htmlName;
            System.out.println("静态化路径："+path);
            Writer file = new FileWriter(new File(path));
            temp.process(root, file);
            file.flush();
            file.close();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (TemplateException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
